package com.example.menuvirtualclient.rule;

import java.util.ArrayList;
import java.util.List;

import com.example.menuvirtualclient.R.drawable;
import com.example.menuvirtualclient.core.Menu;
import com.example.menuvirtualclient.data.*;
import com.example.menuvirtualclient.repository.MenuRepository;
import com.example.menuvirtualclient.util.Common;

import android.R;
import android.content.Context;
import android.graphics.Bitmap;

public class MenuRule {

	private ISession _session;
	private final MenuRepository _repository;

	public MenuRule(Context context) {
		_session = SessionFactory.GetSession(context);
		_repository = new MenuRepository(context);
	}
	

	public List<Menu> GetEntityList() throws Exception {
		try {
			_session.Open();
			return _repository.GetAll();
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
	
	public void deleteAll() throws Exception {
		try {
			_session.Open();
			_repository.Delete();
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
	
	public List<Menu> GetListBySeccion(int seccionId) throws Exception{
		try {
			_session.Open();
			return _repository.GetListBySeccion(seccionId);			
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
/*
	public List<Menu> GetEntityListRight(int seccionId) throws Exception {
		try {
			_session.Open();
			return _repository.GetListByMenyType(seccionId, 2);
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}

	public List<Menu> GetEntityListLeft(int seccionId) throws Exception {
		try {
			_session.Open();
			return _repository.GetListByMenyType(seccionId, 3);
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
	*/
	public Menu Get(int id) throws Exception {
		try {
			_session.Open();
			return _repository.Get(id);
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
	
	public void Insert(Menu entity) throws Exception {
		try {
			_session.Open();
			_repository.Insert(entity);
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
	
	public void Update(Menu entity) throws Exception {
		try {
			_session.Open();
			_repository.Update(entity);
		} 
		catch (Exception ex) {
			throw ex;
		}
		finally{
			_session.Close();
		}
	}
	

}
